/**
 * Rick Jason G Obrero
 * CMSC 190 - AR7 (Danilo J Mercado)
 * 
 * This file contains the main program logic and the view of the
 * MetalCorrosionSimulator.
 */

//Package declaration
package metalcorrosionsimulator;

//Import statements
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.jdesktop.application.Action;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.regex.Pattern;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 * @author Rick Jason G. Obrero
 * @version 1.0
 * @since 1.7
 * The application's main frame.
 */
public class MetalCorrosionSimulatorView extends FrameView {
    private String directory;       //The selected directory of the user.
    private boolean[] fileFound = new boolean[6];   //Specifies files found
    private String[] filenames = {  "ma_s.txt",     //File names
                                    "ma_wd.txt",
                                    "ma_b.txt",
                                    "mi_s.txt",
                                    "mi_wd.txt",
                                    "mi_b.txt"  };
    private String[] filepaths = new String[6];     //File paths

    /**
     * Default constructor. Initializes the components of the frame and disables
     * the to-be-used-later buttons.
     * @param app The SingleFrameApplication which is the parent of this class.
     */
    public MetalCorrosionSimulatorView(SingleFrameApplication app) {
        super(app);
        initComponents();
       
        scanDirectoryButton.setEnabled(false);
        convertFilesButton.setEnabled(false);
    }

    /**
     * Generates the about box.
     */
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = MetalCorrosionSimulatorApp.getApplication()
                    .getMainFrame();
            aboutBox = new MetalCorrosionSimulatorAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        MetalCorrosionSimulatorApp.getApplication().show(aboutBox);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        introLabel = new javax.swing.JLabel();
        one_label = new javax.swing.JLabel();
        one_sublabel = new javax.swing.JLabel();
        one_sublabel2 = new javax.swing.JLabel();
        chooseDirectoryButton = new javax.swing.JButton();
        directoryNameTextBox = new javax.swing.JTextField();
        two_label = new javax.swing.JLabel();
        two_sublabel1 = new javax.swing.JLabel();
        two_sublabel2 = new javax.swing.JLabel();
        scanDirectoryButton = new javax.swing.JButton();
        fileScanResult = new javax.swing.JLabel();
        fileScanResult1 = new javax.swing.JLabel();
        two_label1 = new javax.swing.JLabel();
        two_sublabel3 = new javax.swing.JLabel();
        convertFilesButton = new javax.swing.JButton();
        fileWrittenPrompt = new javax.swing.JLabel();
        exitButton = new javax.swing.JButton();
        four_label = new javax.swing.JLabel();
        frameMenuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(metalcorrosionsimulator.MetalCorrosionSimulatorApp.class).getContext().getResourceMap(MetalCorrosionSimulatorView.class);
        introLabel.setText(resourceMap.getString("introLabel.text")); // NOI18N
        introLabel.setName("introLabel"); // NOI18N

        one_label.setFont(resourceMap.getFont("one_label.font")); // NOI18N
        one_label.setText(resourceMap.getString("one_label.text")); // NOI18N
        one_label.setName("one_label"); // NOI18N

        one_sublabel.setText(resourceMap.getString("one_sublabel.text")); // NOI18N
        one_sublabel.setName("one_sublabel"); // NOI18N

        one_sublabel2.setText(resourceMap.getString("one_sublabel2.text")); // NOI18N
        one_sublabel2.setName("one_sublabel2"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(metalcorrosionsimulator.MetalCorrosionSimulatorApp.class).getContext().getActionMap(MetalCorrosionSimulatorView.class, this);
        chooseDirectoryButton.setAction(actionMap.get("openDirectoryChooser")); // NOI18N
        chooseDirectoryButton.setText(resourceMap.getString("chooseDirectoryButton.text")); // NOI18N
        chooseDirectoryButton.setName("chooseDirectoryButton"); // NOI18N

        directoryNameTextBox.setEditable(false);
        directoryNameTextBox.setText(resourceMap.getString("directoryNameTextBox.text")); // NOI18N
        directoryNameTextBox.setName("directoryNameTextBox"); // NOI18N

        two_label.setFont(resourceMap.getFont("two_label.font")); // NOI18N
        two_label.setText(resourceMap.getString("two_label.text")); // NOI18N
        two_label.setName("two_label"); // NOI18N

        two_sublabel1.setText(resourceMap.getString("two_sublabel1.text")); // NOI18N
        two_sublabel1.setName("two_sublabel1"); // NOI18N

        two_sublabel2.setText(resourceMap.getString("two_sublabel2.text")); // NOI18N
        two_sublabel2.setName("two_sublabel2"); // NOI18N

        scanDirectoryButton.setAction(actionMap.get("scanDirectory")); // NOI18N
        scanDirectoryButton.setText(resourceMap.getString("scanDirectoryButton.text")); // NOI18N
        scanDirectoryButton.setName("scanDirectoryButton"); // NOI18N

        fileScanResult.setText(resourceMap.getString("fileScanResult.text")); // NOI18N
        fileScanResult.setName("fileScanResult"); // NOI18N

        fileScanResult1.setText(resourceMap.getString("fileScanResult1.text")); // NOI18N
        fileScanResult1.setName("fileScanResult1"); // NOI18N

        two_label1.setFont(resourceMap.getFont("two_label1.font")); // NOI18N
        two_label1.setText(resourceMap.getString("two_label1.text")); // NOI18N
        two_label1.setName("two_label1"); // NOI18N

        two_sublabel3.setText(resourceMap.getString("two_sublabel3.text")); // NOI18N
        two_sublabel3.setName("two_sublabel3"); // NOI18N

        convertFilesButton.setAction(actionMap.get("convertFiles")); // NOI18N
        convertFilesButton.setText(resourceMap.getString("convertFilesButton.text")); // NOI18N
        convertFilesButton.setName("convertFilesButton"); // NOI18N
        convertFilesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                convertFiles(evt);
            }
        });

        fileWrittenPrompt.setText(resourceMap.getString("fileWrittenPrompt.text")); // NOI18N
        fileWrittenPrompt.setName("fileWrittenPrompt"); // NOI18N

        exitButton.setAction(actionMap.get("quit")); // NOI18N
        exitButton.setName("exitButton"); // NOI18N

        four_label.setFont(resourceMap.getFont("four_label.font")); // NOI18N
        four_label.setText(resourceMap.getString("four_label.text")); // NOI18N
        four_label.setName("four_label"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(introLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 1045, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(two_label)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(two_sublabel1)
                            .addComponent(two_sublabel2)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(one_label)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(one_sublabel)
                            .addComponent(one_sublabel2)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(chooseDirectoryButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(directoryNameTextBox, javax.swing.GroupLayout.DEFAULT_SIZE, 912, Short.MAX_VALUE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(two_label1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(two_sublabel3))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(scanDirectoryButton, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fileScanResult1, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fileScanResult, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                                .addComponent(four_label, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addComponent(exitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(convertFilesButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fileWrittenPrompt, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(introLabel)
                        .addGap(28, 28, 28)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(one_label)
                            .addComponent(one_sublabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chooseDirectoryButton)
                            .addComponent(directoryNameTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(two_label)
                                    .addComponent(two_sublabel2)))
                            .addComponent(two_sublabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(scanDirectoryButton)
                            .addComponent(fileScanResult)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(one_sublabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fileScanResult1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(two_label1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(two_sublabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(convertFilesButton)
                    .addComponent(fileWrittenPrompt, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(four_label, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exitButton))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        frameMenuBar.setName("frameMenuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        frameMenuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        frameMenuBar.add(helpMenu);

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Converts the files needed that are inside the directory, and outputs the
     * files that are needed by NetLogo.
     * @param evt The event that triggered the action.
     */
    private void convertFiles(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertFiles
        for(String filename : filepaths){
            StringBuilder filenameToWrite = new StringBuilder(filename);
            int index = filenameToWrite.indexOf(".");
            filenameToWrite.insert(index, "_nl");
            File fileToRead = new File(filename);
            File fileToWrite = new File(filenameToWrite.toString());
            Charset charset = Charset.forName("US-ASCII");
            HashMap coeff = new HashMap();
            String[] models =   {   "Harris Model", 
                                    "4th",
                                    "Logistic Model",
                                    "Sinusoidal Fit",
                                    "Quadratic Fit",
                                    "Linear Fit",
                                    "3rd",
                                    "MMF Model",
                                    "Rational Function",
                                    "Exp. Association (3)",
                                    "Exponential Association",
                                    "Modified Geometric",
                                    "Vapor Pressure",
                                    "Reciprocal Logarithm",
                                    "Hoerl Model",
                                    "Power Fit",
                                    "Modified Hoerl",
                                    "Modified Exponential",
                                    "Shifted Power Fit",
                                    "Root Fit",
                                    "Heat Capacity Model",
                                    "Modified Power",
                                    "Exponential Fit",
                                    "Logarithm Fit",
                                    "Reciprocal Quadratic",
                                    "Reciprocal Model",
                                    "Saturation Growth-Rate",
                                    "Gompertz Relation"
                                };
            int model = 0;
            String[] arr;
            BufferedReader reader;
            BufferedWriter writer;
            
            try{
                reader = Files.newBufferedReader(fileToRead.toPath(), charset);
                String line = null;
                String pattern = "^\"(.{2})(\")(.{1,})[0-9]$";
                int line1 = 0;
                while ((line = reader.readLine()) != null) {
                    if(line1 == 0){
                        for(int i = 0; i < models.length; i++)
                            if(line.contains(models[i])) model = i;
                        line1 = 1;
                    }else{				
                        if(Pattern.matches(pattern, line)){
                            arr = line.split("\t");
                            coeff.put(arr[0].charAt(1), arr[1]);
                        }
                    }
                }
                switch(model){
                    case 0: line = "1 / ("+coeff.get('a')+" + (("
                            +coeff.get('b')+" * x) ^ "+coeff.get('c')+"))";
                    break;
                    case 1: line = coeff.get('a')+" + "
                            +coeff.get('b')+" * x + "+coeff.get('c')
                            +" * x ^ 2 + "+coeff.get('d')+" * x ^ 3 + "
                            +coeff.get('e')+" * x ^ 4";
                    break;
                    case 2: line = coeff.get('a')+" / 1 + ("
                            +coeff.get('b')+" * (e ^ (-1 * "+coeff.get('c')
                            +" * x)))";
                    break;
                    case 3: line = coeff.get('a')+" + "+coeff.get('b')+
                            " * cos (("+coeff.get('c')+" * x) * "+coeff.get('d')
                            +")";
                    break;
                    case 4: line = coeff.get('a')+" + "
                            +coeff.get('b')+" * x + "+coeff.get('c')
                            +" * x ^ 2";
                    break;
                    case 5: line = coeff.get('a')+" + "
                            +coeff.get('b')+" * x";
                    break;
                    case 6: line = coeff.get('a')+" + "
                            +coeff.get('b')+" * x + "+coeff.get('c')
                            +" * x ^ 2 + "+coeff.get('d')+" * x ^ 3";
                    break;
                    case 7: line = "("+coeff.get('a')+" * "+coeff.get('b')+" + "
                            +coeff.get('c')+" * ( x ^ "+coeff.get('d')+" )) / ("
                            +coeff.get('b')+" + ( x ^ "+coeff.get('d')+" ))";
                    break;
                    case 8: line = "("+coeff.get('a')+" + ( "+coeff.get('b')+
                            " * x)) / ( 1 + "+coeff.get('c')+" * x + "+
                            coeff.get('d')+" * (x ^ 2))";
                    break;
                    case 9: line = "("+coeff.get('a')+" * ("+coeff.get('b')+
                            " - ( e ^ ( - "+coeff.get('c')+" * x))))";
                    break;
                    case 10: line = "("+coeff.get('a')+" * ( 1 - ( e ^ ( - "+
                            coeff.get('c')+" * x))))";
                    break;
                    case 11: line = "("+coeff.get('a')+" * ( x ^ ( "+
                            coeff.get('b')+" * x )))";
                    break;
                    case 12: line = "e ^ ( ( "+coeff.get('a')+" ) + ( ( "+
                            coeff.get('b')+" / x ) ) + ( ( "+coeff.get('c')+" )"
                            + " * ln x ))";
                    break;
                    case 13: line = "1 / ( "+coeff.get('a')+" + "+coeff.get('b')+
                            " * ln x )";
                    break;
                    case 14: line = coeff.get('a')+" * ( "+coeff.get('b')+" ^ x)"
                            + " * ( x ^ "+coeff.get('c')+" )";
                    break;
                    case 15: line = coeff.get('a')+" * ( x ^ "+coeff.get('b')+" )";
                    break;
                    case 16: line = coeff.get('a')+" * ( "+coeff.get('b')+" ^ (1"
                            + " / x) ) * ( x ^ "+coeff.get('c')+" )";
                    break;
                    case 17: line = coeff.get('a')+" * ( e ^ ("+coeff.get('b')+" / x ))";
                    break;
                    case 18: line = coeff.get('a')+" * ( ( x - "+coeff.get('b')+" ) ^ "+
                            coeff.get('c')+" ) ";
                    break;
                    case 19: line = coeff.get('a')+" * ( "+coeff.get('b')+" ^ (1 / x))";
                    break;
                    case 20: line = coeff.get('a')+" + ( "+coeff.get('b')+" * x ) + "
                            + "( "+coeff.get('c')+" / (x ^ 2) )";
                    break;
                    case 21: line = coeff.get('a')+" * ( "+coeff.get('b')+" ^ x)";
                    break;
                    case 22: line = coeff.get('a')+" * ( e ^ ( "+coeff.get('b')+" * x ))";
                    break;
                    case 23: line = coeff.get('a')+" + ( "+coeff.get('b')+" * ln x)";
                    break;
                    case 24: line = "1 / ( "+coeff.get('a')+" + "
                            +coeff.get('b')+" * x + "+coeff.get('c')
                            +" * x ^ 2 )";
                    break;
                    case 25: line = "1 / ( "+coeff.get('a')+" + "
                            +coeff.get('b')+" )";
                    break;
                    case 26: line = "( "+coeff.get('a')+" * x) / ( "+coeff.get('b')+
                            " + x )";
                    break;
                    case 27: line = "( "+coeff.get('a')+" * ( e ^ ( -1 * ( e ^ ( "+
                            coeff.get('b')+" - ( "+coeff.get('c')+" * x))))))";
                    break;
                        
                }
                
                try{
                    writer = new BufferedWriter(new FileWriter(
                            fileToWrite.toPath().toString()));
                    writer.write(line);
                    writer.close();
                }catch (IOException x) {}
            }catch (IOException x) {}
        }
        fileWrittenPrompt.setText("Files are written.");
        chooseDirectoryButton.setEnabled(false);
        scanDirectoryButton.setEnabled(false);
        convertFilesButton.setEnabled(false);
    }//GEN-LAST:event_convertFiles

    /**
     * This chooses the source directory of the text files needed to be
     * converted.
     */
    @Action
    public void openDirectoryChooser() {
        JFileChooser directoryChooser = new JFileChooser();
        directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        directoryChooser.setApproveButtonText("Choose");
        directoryChooser.setDialogTitle("Choose Directory...");
        int returnVal = directoryChooser.showOpenDialog(this.getComponent());
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            directory = directoryChooser.getSelectedFile().getAbsolutePath();
            directoryNameTextBox.setText(directory);
            scanDirectoryButton.setEnabled(true);
        }
    }

    /**
     * Scans the directory chosen for proper files.
     */
    @Action
    public void scanDirectory() {
        fileScanResult.setText("File scan result will be displayed here.");
        boolean filesFound = true;
        String filename = "";
        for(int i = 0; i < 6; i++){
            fileFound[i] = true;
            filename = "";
            filename = directory.concat("\\");
            filename = filename.concat(filenames[i]);
            filepaths[i] = filename;
            File fileHander = new File(filename);
            if(!Files.exists(fileHander.toPath())){
                fileFound[i] = false;
                filesFound = false;
            }
        }
        if(!filesFound){
            fileScanResult.setText("Some files are not found.");
            StringBuilder files = new StringBuilder();
            for(int i = 0; i < 6; i++){
                if(!fileFound[i]){
                    if(files.length() != 0) files.append(", ");
                    files.append(filenames[i]);
                }
            }
            fileScanResult1.setText(files.toString());
        }else{
            fileScanResult.setText("All files are found.");
            fileScanResult1.setText("");
            convertFilesButton.setEnabled(true);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton chooseDirectoryButton;
    private javax.swing.JButton convertFilesButton;
    private javax.swing.JTextField directoryNameTextBox;
    private javax.swing.JButton exitButton;
    private javax.swing.JLabel fileScanResult;
    private javax.swing.JLabel fileScanResult1;
    private javax.swing.JLabel fileWrittenPrompt;
    private javax.swing.JLabel four_label;
    private javax.swing.JMenuBar frameMenuBar;
    private javax.swing.JLabel introLabel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel one_label;
    private javax.swing.JLabel one_sublabel;
    private javax.swing.JLabel one_sublabel2;
    private javax.swing.JButton scanDirectoryButton;
    private javax.swing.JLabel two_label;
    private javax.swing.JLabel two_label1;
    private javax.swing.JLabel two_sublabel1;
    private javax.swing.JLabel two_sublabel2;
    private javax.swing.JLabel two_sublabel3;
    // End of variables declaration//GEN-END:variables

    private JDialog aboutBox;
}
